#include "eeprom.h"
#include "i2c_hal.h"

#define delay1 HAL_Delay

/**
 * @brief 24C02写，按字节
 */
void iic_24c02_write(uint8_t *pucBuf, uint8_t ucAddr, uint8_t ucNum)
{
    I2CStart();
    I2CSendByte(0xa0);
    I2CWaitAck();

    I2CSendByte(ucAddr);
    I2CWaitAck();

    while(ucNum--)
    {
        I2CSendByte(*pucBuf++);
        I2CWaitAck();
    }
    I2CStop();
    delay1(500);
}

/**
 * @brief 24C02读，按字节
 */
void iic_24c02_read(uint8_t *pucBuf, uint8_t ucAddr, uint8_t ucNum)
{
    I2CStart();
    I2CSendByte(0xa0);
    I2CWaitAck();

    I2CSendByte(ucAddr);
    I2CWaitAck();

    I2CStart();
    I2CSendByte(0xa1);
    I2CWaitAck();

    while(ucNum--)
    {
        *pucBuf++ = I2CReceiveByte();
        if(ucNum)
            I2CSendAck();
        else
            I2CSendNotAck();
    }
    I2CStop();
}
